package com.zsl.util;

import com.zsl.model.Users;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ListToJSON {
    public static Map<String, String> UsersListToJSON(List<Users> users) {
        StringBuilder s = new StringBuilder();
        Integer total=0;
        s.append("[");
        for (Users user : users) {
            total++;
            s.append("{");
            s.append("\"uid\":").append("\"").append(user.getUid()).append("\"").append(",");
            s.append("\"uname\":").append("\"").append(user.getUname()).append("\"").append(",");
            s.append("\"pwd\":").append("\"").append(user.getPwd()).append("\"").append(",");
            s.append("\"hobby\":").append("\"").append(user.getHobby()).append("\"");
            s.append("},");
        }
        s.deleteCharAt(s.length() - 1);
        s.append("]");
        Map<String, String> tmp = new HashMap<>();
        tmp.put("rows", s.toString());
        tmp.put("total",total.toString());
        return tmp;
    }
}
